#include <stdio.h>
#include <rpc/rpc.h>
#include "xdr.h"
#include "../ndmp_ioctl.h"


int open_tapedrive(struct ndmp_session_detail *nh, char *name);
int list_devices(struct ndmp_session_detail *nh);

int init_ndmp_handle (struct ndmp_session_detail *);

int ndmp_connect(struct sockaddr_in *);

int read_stream(char *,char *, int);

int write_stream(char *,char *, int);

int do_ndmp_authenticate ( struct ndmp_session_detail *);

int get_host_info ( struct ndmp_session_detail *, ndmp_config_get_host_info_reply *);
int get_server_info ( struct ndmp_session_detail *, ndmp_config_get_server_info_reply *);
int get_device_info ( struct ndmp_session_detail *, ndmp_config_get_device_info_reply *, ndmp_message);


int device_open( struct ndmp_session_detail *, char *, ndmp_message, ndmp_tape_open_mode);
int device_close( struct ndmp_session_detail *, ndmp_message);


int prepare_ndmp_header( struct ndmp_session_detail *, ndmp_message);
int recieve_ndmp_header( struct ndmp_session_detail *);


char *errorp(int);

#define P_E 0xA0
#define S_E 0xD0
#define N_E 0xE0
#define STAT 0xF0

#define NDMP_ERROR(code) (code==0) ? (0) : ( (P_E) + (code) )
#define SCSI_ERROR(code) (code==0) ? (0) : ( (S_E) + (code) )
#define NET_ERROR(code) (code==0) ? (0) : ( (N_E) + (code) )

#define STATE_UNINITIALIZED -1
#define STATE_TCP_CONNECTED 0
#define STATE_CONNECTION_ACCEPTED 1
#define STATE_AUTHENTICATED 2
#define STATE_DEVICE_OPEN 3

#define MAX_IO_SIZE 131072
